'''我的画散点图'''
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
#下面两句代码防止中文显示成方块
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']

plt.rcParams['figure.dpi'] = 300 #图片像素
plt.rcParams['figure.figsize'] = (12.0, 4.0)

# x_bits = [12, 24, 32, 48]
x_bits = [4.3, 4.3, 4.4, 5.3, 2.5]

def joint_early():

    with PdfPages('joint_early.pdf') as pdf:
        plt.subplot(1, 2, 1)#sun部分画在子图1中
        # 数据准备
        x =  [4.3, 4.4, 5.3, 2.5]
        y = [94.8, 92.4, 89.2, 77.1]
        txt = ['94.8', '92.4', '89.2', '77.1']
        # 开始绘制
        colors = ['r', 'greenyellow', 'darkorange', 'darkblue']
        markers = ['*', '^', 'd', 'o']
        linewidth =[0.8, 0.1, 0.1, 0.1]
        labels = ['EfficientFcos-SPP',  'EfficientFcos', 'CSPDarknet+Fcos', 'EfficientDet',]
        plt.plot(x, y, color='cornflowerblue', linestyle='-', linewidth = 1.2)
        for i in range(4):
            plt.scatter(x[i], y[i], c=colors[i], marker=markers[i],label=labels[i],linewidths=linewidth[i])
            plt.annotate(txt[i], xy=(x[i], y[i]), xytext=(x[i] + 0.1, y[i] - 0.1))
        plt.xlim(2,6)  # 横轴只有这四个刻度
        plt.xlabel("FLOPs(Billions)",fontsize=6)  # 作用为横坐标轴添加标签  fontsize=12
        plt.ylim(40, 100)       #y坐标范围
        # plt.title("SUN")
        plt.ylabel("mAP",fontsize=8)  # 作用为纵坐标轴添加标签
        plt.legend()
        plt.show()
        # pdf.savefig()  # 如果要保存，就需要去掉plt.show()，因为plt.show()会把figure清除掉
joint_early()

'''画线性规划图1'''
import numpy as np
import matplotlib.pyplot as plt
#%matplotlib inline
# from pylab import figure, text, scatter, show
# Construct lines

x = np.linspace(0, 10, 100)
M = [[0,1.5]]
N = [[5,3.5]]
y1 = x + 2
y2 = 2*x-5
y3 = -x + 4
# y4 = -x + 5
# Make plot
plt.plot(x, y1,  c='black')
plt.plot(x, y2,  c='black')
plt.plot(x, y3,  c='black')
plt.plot(M[0], N[0],  c='black',linestyle = '--')
# plt.scatter(M[0], N[0],  c='black',linestyle = '--')
# plt.plot(x1, y, c='black', linewidth = 2.0)
# plt.axvline(0,0,120,c='black')

plt.annotate(r'$x-y+2=0$',xy=(4,6),xycoords='data',xytext=(-60,+5),
             textcoords='offset points',fontsize=10)
plt.annotate(r'$2x-y-5=0$',xy=(5,5),xycoords='data',xytext=(+7,+5),
             textcoords='offset points',fontsize=10)
plt.annotate(r'$x+y-4=0$',xy=(4,0),xycoords='data',xytext=(-5,+10),
             textcoords='offset points',fontsize=10)
# plt.annotate(r'$x=0$',xy=(0,40),xycoords='data',xytext=(+5,-10),
#              textcoords='offset points',fontsize=10)
#
plt.annotate(r'A',xy=(1, 3),xycoords='data',xytext=(-5,-15),
             textcoords='offset points',fontsize=13)
plt.annotate(r'B',xy=(3,1),xycoords='data',xytext=(+5,-5),
             textcoords='offset points',fontsize=13)
plt.annotate(r'C(7,9)',xy=(7,9),xycoords='data',xytext=(+1,-10),
             textcoords='offset points',fontsize=13)
plt.annotate(r'M(0,5)',xy=(0,5),xycoords='data',xytext=(-10,5),
             textcoords='offset points',fontsize=10)
plt.annotate(r'N',xy=(1.5,3.5),xycoords='data',xytext=(-5,+7),
             textcoords='offset points',fontsize=13)

plt.xlim((0, 10))
plt.ylim((0, 10))
plt.xlabel(r'$x$')
plt.ylabel(r'$y$')

# Fill feasible region
# y5 = np.minimum(y1, y3)
y6 = np.maximum(y2, y3)
plt.fill_between(x, y6, y1, where=y6 < y1, color='grey', alpha=0.5)

plt.grid(True, linestyle='-.')
# plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) #加label
# plt.savefig('ordering_constraints.eps',dpi=600,bbox_inches='tight')
plt.show()

